function [ obj ] = evaluate_perturb(weight)
%UNTITLED4 Summary of this function goes here
%   Detailed explanation goes here
global idx 
global relevant_idx
global target_hover_state
global H
global dt
global model

t_hist = [];
for i = 1:10
K = reshape(weight, [length(idx.inputs) length(relevant_idx)]);
start_ned = 5*rand(3,1) - 2.5*ones(3,1);
rotation_axis = normc(randn(3,1));
rotation_angle = 2*pi*rand(); % radians
start_q = [sin(rotation_angle/2)*rotation_axis; cos(rotation_angle/2)];
basin = 15;

start_state = target_hover_state;
start_state(idx.ned) = start_ned;
start_state(idx.q) = start_q;

x(:,1) = start_state;
for t=1:H   
    dx = compute_dx(target_hover_state, x(:,t));
    delta_u = K*dx(relevant_idx);
    x(:,t+1) = f_heli(x(:,t), delta_u, dt, model, idx);
    if(norm(x(idx.ned,t+1) - target_hover_state(idx.ned,:)) > basin)
        break;
    end
end
t_hist = [t_hist t];
end
obj = -mean(t_hist);

end

